package com.mentaleye.biz.impl;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.mentaleye.bean.RoleBean;
import com.mentaleye.biz.RoleBiz;
import com.mentaleye.dal.model.RoleExample;
import com.mentaleye.service.RoleService;
import com.mentaleye.util.CommonPage;
import com.mentaleye.util.CommonResult;
@Service
public class RoleBizImpl implements RoleBiz {

	@Autowired private RoleService roleService;
	private static Logger logger = Logger.getLogger(RoleBizImpl.class);
	@Override
	public CommonResult editRole(RoleBean roleBean) {
		CommonResult result = new CommonResult();
		boolean add;
		boolean success = false;
		add = roleBean.getRoleNo()==null;
		try {
			success = roleService.editRole(roleBean, add);
		} catch (Exception e) {
			logger.error("编辑角色异常", e);
			success = false;
		}
		result.setIsSuccess(success);
		return result;
	}

	@Override
	public CommonResult dropRole(Integer ids) {
		try {
			return new CommonResult(roleService.deleteRoleByList(ids));
		} catch (Exception e) {
			logger.error("删除角色异常", e);
			return new CommonResult();
		}
		
	}

	@Override
	public List<RoleBean> getAllRole() {
		try {
			List<RoleBean> roleList = roleService.queryAllRole(new RoleExample());
			return roleList;
		} catch (Exception e) {
			logger.error("查询所有角色异常", e);
			return null;
		}
		
	}

	@Override
	public void getRoleBypage(CommonPage commonPage) {
		try {
			roleService.queryRoleByPage(commonPage);
		} catch (Exception e) {
			logger.error("分页查询角色异常", e);
		}

	}

	@Override
	public RoleBean getRoleByNo(Integer roleNo) {
		return roleService.queryRoleByNo(roleNo);
	}

}
